package com.huifaapp.mall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.activity.EvaluateActivity;
import com.huifaapp.mall.uitils.GlideUtils;

import java.util.ArrayList;
import java.util.List;

public class EvaluateImageAdapter extends BaseAdapter {
    LayoutInflater layoutInflater;
    private List<String> mDatas = new ArrayList<>();

    private Context mContext;

    public EvaluateImageAdapter(Context mContext) {
        this.mContext = mContext;
        layoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public String getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = layoutInflater.inflate(R.layout.item_evaluate_image, null);
     ImageView   mImageView = (ImageView) convertView.findViewById(R.id.iv_image);

        String itemData = mDatas.get(position);

        if (itemData.equals(EvaluateActivity.DEFAULT_ADD)) {

            mImageView.setBackgroundResource(R.drawable.bg_tianjia);//最后一个显示加号图片
        } else {
            GlideUtils.loadImageView(mContext,mDatas.get(position),mImageView);
        }


//        if (position < mDatas.size()) {
//
//            GlideUtils.loadImageView(mContext,mDatas.get(position),mImageView);
//        }else{
//
//            if (getCount() < mDatas.size()) {
//
//
//                mImageView.setBackgroundResource(R.drawable.bg_tianjia);//最后一个显示加号图片
//                mImageView.setVisibility(View.VISIBLE);
//            } else {
//                mImageView.setVisibility(View.GONE);
//            }
//        }
        return convertView;
    }


    public  void  setNewData(List<String>  newList){

        mDatas.clear();
        mDatas.addAll(newList);
        notifyDataSetChanged();

    }

    public  void  addDatas(List<String> list){

    mDatas.addAll(list);
        notifyDataSetChanged();

    }
}
